What are you doing btw ? $letter2 will have the first character of $letter. And, it works for me!
$letter2 = $letter{0};
What are you doing btw ? $letter2 will have the first character of $letter. And, it works for me!
$letter2 = $letter{0};
umm.. Can you post your code ?
You are welcome :)
:) Yep! lol.. Sometimes it happens..
In your above script, you are getting the records to $result. But you aren't printing anywhere. Try printing out $result somewhere.
When you use select query, you need to 'fetch' the rows and display it. You do it this way.
<?php
//connect
//select db
$query = "select * from table where id='$id'";
$result = mysql_query($query);
while($row = mysql_fetch_array($result)){
echo $row['firstname'];
echo $row['lastname'];
//etc..
}
:) Cheers..
You should actually try and avoid using
SELECT *
and rather list the columns you want to be returnedSELECT [I]col1, col2, col3[/I]
It just helps speeding things up a bit and you don't have a ton of data flying around the web that you don't need.
Very true. But if you don't know what columns you wanna display and what not, you can use *.
Where are you trying to display the records ?
Update query is correct. But select query is wrong.
SELECT * FROM cms_core WHERE id= '1'
You can use this.
And you don't have that syntax error anymore. Right ? Now, if that solves your problem, well and good. If it doesn't, you need to be specific about your problem.
Then obviously, the table has records. What do you want exactly ?
Huh! Can you post your complete code ?
$res will have the resource_id of the query you just executed. You can check if there are any records or not this way.
$res = mysql_query($SQL,$db);
if(mysql_num_rows($res) > 0){
echo "There is something!";
} else {
echo "Nothing !";
}
Syntax error while updating the record or while fetching ?
$SQL = "SELECT cms_core FROM '$sContent' WHERE id=1";
$sql="UPDATE cms_core SET editorial='$sContent' WHERE id=$id";
cms_core ? is it a table or a column name ?
$query = "select * from table where username='username_value' and password='password_value'";
$result = mysql_query($query);
$row = mysql_fetch_array($result); // if you query returns only 1 row
//while($row = mysql_fetch_array($result){ if your query returns more than 1 row
$firstname=$row['firstname_column'];
$lastname=$row['lastname_column'];
//and so on..
I hope thats clear ?
If it was successful in connecting, why would it say access denied ?
Welcome Luc!
When the user logs in, check if its a valid login. If, yes, then query the table which has the user details for this username. Since this is a login script, username has to be unique. So, a username can have only 1 row of details.
<?php
//connection
//get the form variables values
//check for valid login
if (true) {
$query = "select * from table where username='username_value_'";
//get the details
}
The more simple way is to query the table while checking for valid username.
<?php
//connection
//get the form variables
$query = "select * from table where username='username_value' and password='password_value'";
//if mysql returns more than 0 rows display his details. If its an invalid details, display error message or redirect back to login page.
You can check out w3schools for php-mysql tutorial.
Cheers,
Naveen
You dont need <?= because you are already echoing something ! You can do this.
echo "<form name=\"tsgh_add\" method=\"post\" action=".$_SERVER['PHP_SELF']." onSubmit=\"return checkWholeForm(this);\">";
Dude, you have to be specific on the errors you get. What do you mean by 'error on mysql_num_row' ? What is the error ?
Try this.
unction exequery($query){
if (!$this->conn) {
die('Could not connect: ' . mysql_error());
}
echo $query;
exit;
$results = mysql_query($query) or die(mysql_error());
//mysql_close($this->conn);
return $results;
}
Check if its printing the query. Also in the class, check if database connection is established.
Return some value on execution of the delete query. Check if its returning the right value.
but its not doing it
Which part of the script isn't working ? Executing the delete query or establishing the connection ?
textbox inside <?php tags ? Yep, you have to echo it. But this way. echo "<input type=\"text\" name=\"name\" value=\"$firstname\">";
http://www.w3schools.com/php/php_mysql_select.asp Check this. Instead of echoing $row and $row in the example, assign it to a variable and use it as the 'value' of the textbox. <input type="text" name="firstname" value="<?php echo $firstname; ?>">
:) You are welcome!
Use a variable with another name.. not $weekday ! :)
Huh! thats strange. Before foreach loop, assign null to $weekday and then try again !
Edit: Or, use another variablename $weekday1. Check this example.
<?php
echo $id;
?>
<html>
<body>
<form method="post" action='test.php'>
<input type=text name=id[]><br>
<input type=submit name=submit value=submit>
</form>
</body>
</html>
Form variables are global by default. (I think).
Basically, its like this. You have for example 3 pages. homepage.php, courses.php and students.php.
homepage.php is a login script, where the user can login. You should check if the user is a valid user. You shouldn't let the user to go to page2 or page3 (ie., courses.php and students.php) if the user hasn't logged in. For this, you can use sessions. Once the user has logged in, add his username to the session. ($_SESSION=$username; ). Then on page2 and page3, check if $_SESSION is not null. If its null, then he isn't a valid user, so redirect him back to homepage.php. If he's a valid user, show him page2. That can be done as shown by petr.pavel in post2.
during each while loop, print out what's in $sum.
while($a_row= mysql_fetch_assoc($result)) {
echo "<tr><td style=\"color:Black\">".$a_row
['DayofWeek']."</td>".
"<td style=\"color:Black\">".$a_row['Bookingdate']."</td>".
"<td style=\"color:red\">".$a_row['Total']."</td></tr>";
$sum=$sum+$a_row['Total'];
echo $sum;
}
Have another variable which adds $a_row value.
$sum=0;
while($a_row= mysql_fetch_assoc($result)) {
echo "<tr><td style=\"color:Black\">".$a_row['DayofWeek']."</td>".
"<td style=\"color:Black\">".$a_row['Bookingdate']."</td>".
"<td style=\"color:red\">".$a_row['Total']."</td></tr>";
$sum=$sum+$a_row['Total'];
}
By the end of the loop, $sum will have the total of $a_row.
hmm.. AFAIK, only mysql uses port 3306. To check what ports are being used, open command prompt and type netstat -ab. It ll list all the applications and the ports used by those applications.
Maybe that port is blocked by your firewall ?
Here is a simple example.
This is test.php
<html>
<head>
<script type="text/javascript">
function popup(){
window.open("popup.php","100","100");
}
</script>
</head>
<body>
<form name="test">
<a href="#" onclick="javascript:popup();">Login</a>
</form>
</body>
</html>
And this is the popup.
<html>
<head>
<?php
if(isset($_POST['submit'])){
if($_POST['name'] == "test") {
echo "<script type='text/javascript'>window.opener.location='test2.php'</script>";
} else {
echo "<script type='text/javascript'>window.opener.location='http://www.google.com'</script>";
}
}
?>
</head>
<body>
<form method="post" action="popup.php">
Name: <input type="text" name="name"><br />
<input type="submit" name="submit" value="submit">
</form>
</body>
</html>
In the popup, if the user inputs name as test, it will redirect the parent window to test2.php and if its wrong, it will redirect to google.com :)
Cheers,
Naveen
Yep.. Thats what window.opener will do..
See http://www.w3schools.com/htmldom/met_win_open.asp for popup..
see http://www.w3schools.com/htmldom/prop_win_opener.asp to update/refresh/relocate the parent window.
Thats strange. Put the connection string as 1st line of your code. Is it entering all the other conditions ?
hmm! instead of $con=mysql_connect('localhost','root','password'); give $con=mysql_connect('localhost','root','password') or die(mysql_error());
I dont think establishing the connection is the problem. If that was the problem, you would have got an error message while executing the script. Anyway, change the connection string line as above and try again !
Hi every one,
Why I am getting wrong time when I am using date('H:i:s').I am working on localhost.
Please help how to get correct time.Thanks and Regards,
Aravind Kishore.P
hmm.. Because it displays the time in UTC. If you want the exact time, add the time difference using mktime.
Eg.
<?php
echo date("H:i:s",mktime(date("H")+5, date("i")+30, date("s"))); //this will display current indian time because the difference is 5 hrs 30 mins.
?>
Cheers,
Naveen
hie
my fujitsu siemens amilo pro v3515 laptop with vista home basic has been displaying windows resuming when i switch it on ..been going on for 2 days...cannot get any of the keys to do anything...can anyone help?????.. thanx
You need to post this question in hardware forum.
Umm.. echo statements to check the flow of the code. Check if its entering the loops correctly. Check the form variable names. Put print_r($_POST); on top of the page to see if all the form variables are posted properly.
select * from table where keyword like "%$keyword%";
$keyword = user input.
Try this..
<?php
if(isset($_POST['submit'])){
if(!empty($_POST["name"]) && !empty($_POST["pass"]) && !empty($_POST["email"]))
{
$name=$_POST["name"];
$pass=$_POST["pass"];
$email=$_POST["email"];
$con=mysql_connect('localhost','root','password');
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("users");
$sql = "INSERT INTO members (username,password,email) VALUES ('$name','$pass','$email')";
$query = mysql_query($sql) or die('Error: ' . mysql_error());
echo "Inserted successfully !";
} else {
echo "Fields can't be empty !";
}
}
?>
<html>
<body>
<form action="register.php" method="post">
Username: <input type="text" name="name" /></br>
Password: <input type="password" name="pass" /></br>
Email: <input type="text" name="email" width=40 /></br>
<input type="submit" name="submit" value="submit" />
</form>
</body>
</html>
echo "<tr bgcolor=$bg>"; instead of echo "<tr>";
Yep. Or you can write the comments to a file and then display the contents of that file.
Very simple. List all the comments in the table(if any), have a textarea and a button. When the button is clicked, add the contents of textarea to the comments column.
Eg.
<?php
//connect
//select db
if(isset(submit button)){
if(!empty(textarea){
//insert into table (comments) values (textarea_contents)
}
}
//query to display the poem.
//print the poem.
$q="select comments from table where poem_id=$id";
//print the comments
?>
<form>
<textarea name=comments></textarea>
<submit button>
</form>
yep. print out the array values by using print_r($test). You will know what values does the array $test contains.