I am new to PHP. I wanted to create a new record in another table but just one new variable gets returned. I've tried following:
$user_id = mysql_real_escape_string($_POST['user_id']);
$user_name = mysql_query("SELECT user_name FROM accept WHERE user_id=".$user_id." ");
$row1 = mysql_fetch_array($user_name);
$server = mysql_query("SELECT server FROM accept WHERE user_id=".$user_id." ");
$row2 = mysql_fetch_array($server);
$url = mysql_query("SELECT link FROM accept WHERE user_id=".$user_id."");
$row3 = mysql_fetch_array($url);
$lpoints = mysql_real_escape_string($_POST['lpoints']);
And my result is this.
mysql_fetch_array()
returns an array, not a scalar value. You are inserting those arrays directly, which PHP represents asArray
. You mean to do things like$row3 = mysql_fetch_array($url); $url = $row3['url'];
However, you should get all of these in one query.SELECT user_name, server, link FROM accept WHERE user_id = $user_id
– Michael Berkowski Aug 2 '14 at 21:48var_dump($row1)
for example to see what the return looks like. – Michael Berkowski Aug 2 '14 at 21:48mysql_*()
functions. They are deprecated and will soon be removed from PHP. Instead, you should begin using PDO or MySQLi, with prepared statements. See this question for practical examples of both. This excellent PDO tutorial places PDO in context of themysql_*()
functions if you're already familiar with those. – Michael Berkowski Aug 2 '14 at 21:49