Jump to content

trying to retrieve info but SELECT command not working


bruceleejr

Recommended Posts

I have a few fields in the "testing" table, Im only trying to retrieve information from the "fn" & "ln" fields which stand for First Name and Last Name

 

Its outputting the custom error message "cant select tables"

 

Hmm whats the problem~???

 

<?
mysql_connect('mysql5.000webhost.com', 'a3393387_c2use', '******', 'a3393387_c2db') or die('error conecint');
echo "Connected to database <br />";
$query = "SELECT * FROM testing";
$result = mysql_query($query) or die('cant select tables');
while($row = mysql_fetch_array($result));{
echo $row['fn'] . " - " . $row['ln'];
echo "<br />";
}

?>

 

its this page

http://testo.comoj.com/grab.php

 

Some extra details:

Apache ver.  2.2.13 (Unix)

PHP version 5.2.*

MySQL ver. 5.0.81-community

Worked perfect~!

 

Everytime you submit something here "http://testo.comoj.com/custom2.html" it gets outputted here "http://testo.comoj.com/custom2.php" which is what I want =]

 

But now since I got  "-" the dash to seperate the fields, a line of dashes gets inserted into the database.

 

Watch, refresh the custom2.php and it automatically creates a new line of dashes that inserted into the database.

 

How can I stop that~??

<?
$fn = $_POST["fn"];
$ln = $_POST['ln'];
$ff = $_POST['ff'];
$fh = $_POST['fh'];
$yb = $_POST['yb'];
$mar = $_POST['mar'];
$dbc = mysqli_connect('mysql5.000webhost.com', 'a3393387_c2use', '******', 'a3393387_c2db')
or die('Cant connect to MySQL servies~!!');

$query = "INSERT INTO testing (fn,ln, " . "
ff, fh, yb, mar) " . "
VALUES ('$fn', '$ln', '$ff', '$fh', '$yb', '$mar')";

$result = mysqli_query($dbc, $query)
or die('error querying database');




mysql_connect('mysql5.000webhost.com', 'a3393387_c2use', '******') or die('error conecint');
echo "Connected to mysql~! <br />";
mysql_select_db('a3393387_c2db');
echo "Connected to database~! <br />";
echo "<b>Displaying details...</b> <br /><br />";
$query1 = "SELECT * FROM testing";
$result1 = mysql_query($query1) or die('cant select tables');
while($row = mysql_fetch_array($result1)) {
echo $row['fn'] ."-". $row['ln'] ."-". $row['ff'] ."-". $row['fh'] ."-". $row['yb'] ."-". $row['mar'];
echo "<br />";
}





mysqli_close($dbc);
?>

<a href="custom2.html">go back to steve's info form</a>

You can test for just the dashes, or do not incorporate the dashes and separate it into 3 different fields and just combine the fields if they are not empty.

 

Unable to really see what you are talking about as the site errors out to a checking for malicious content page.

OKay fill this out here http://testo.comoj.com/stuff/custom4.html

 

It'l get outputted to here http://testo.comoj.com/stuff/custom4.php

 

Heres the code:

 

<?
$fn = $_POST["fn"];
$ln = $_POST['ln'];
$ff = $_POST['ff'];
$fh = $_POST['fh'];
$yb = $_POST['yb'];
$mar = $_POST['mar'];
$dbc = mysqli_connect('mysql5.000webhost.com', 'a3393387_c2use', 'usmc72', 'a3393387_c2db')
or die('Cant connect to MySQL servies~!!');

$query = "INSERT INTO testing (fn,ln, " . "
ff, fh, yb, mar) " . "
VALUES ('$fn', '$ln', '$ff', '$fh', '$yb', '$mar')";

$result = mysqli_query($dbc, $query)
or die('error querying database');




mysql_connect('mysql5.000webhost.com', 'a3393387_c2use', 'usmc72') or die('error conecint');
echo "Connected to mysql~! <br />";
mysql_select_db('a3393387_c2db');
echo "Connected to database~! <br />";
echo "<b>Displaying details...</b> <br /><br />";
$query1 = "SELECT * FROM testing";
$result1 = mysql_query($query1) or die('cant select tables');
while($row = mysql_fetch_array($result1)) {
echo $row['fn'] ."-". $row['ln'] ."-". $row['ff'] ."-". $row['fh'] ."-". $row['yb'] ."-". $row['mar'];
echo "<br />";
}





mysqli_close($dbc);
?>

<a href="custom4.html">go back to steve's info form</a>

 

If you refresh the page a new line of dashes will appear ABOVE the recently inserted data

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.